{extend name="./tpl/default/mobile/public/layout.html" /}
{block name="header"}

<link rel="stylesheet" href="/public/home/mobile/css/guanjian/anli.css">
<link rel="stylesheet" href="/public/home/mobile/css/guanjian/gonglv.css">
<link rel="stylesheet" href="/public/home/mobile/css/guanjian/shouhuodizhi.css">
<style>
    .active{
        border: solid #1AAD19;
    }
</style>
{/block}
{block name="head"}
<div class="am-g" style="margin-top: 20px;font-size:20px; width: 100%;
    text-align: center;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;">

    <div class="am-u-sm-12" style="margin-right: 30px; width: 100%;
    text-align: center;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;">
        订单支付
    </div>
</div>
<hr style="border:1px solid #e0e0e0;">
{/block}
{block name="body"}
<div class="am-g" style="overflow: hidden;white-space: nowrap;">
    <div class="am-u-sm-12">
        <p>订单号：{$orderInfo.order_sn}</p>
    </div>
    <hr style="border:2px solid #dddddd;">
    <hr style="border:2px solid #dddddd;">
    <div class="am-u-sm-12">
        <p>订单信息</p>
    </div>
    <div class="am-u-sm-12">
        <p>保证金：<span style="color:red;">{$orderInfo.margin}元</span></p>
    </div>
    <div class="am-u-sm-12">
        <p>集采数量：<span style="color:red;">{$orderInfo.num}{$orderInfo.goods_unit}</span></p>
    </div>
    <div class="am-u-sm-12">
    </div>
    <hr style="border:2px solid #dddddd;">
    <div class="am-u-sm-12">
        <p>支付信息</p>
    </div>
    <form action="" method="post" id="form">

        <input type="hidden" name="openid" value="{$Request.param.openid}"/>
        <input type="hidden" name="device" id="device" value="{$device}"/>
        <input type="hidden" name="site_id" value="{$orderInfo.site_id}"/>
        <input type="hidden" name="order_type" id="orderType" value="groupbuy_cart"/>
        <input type="hidden" name="order_sn" value="{$orderInfo.order_sn}"/>
        <input type="hidden" name="pay_code" value=""/>
        {volist name="payment" id="vo"}
        <div class="am-u-sm-3" onclick="setPay(this)" data-code="{$vo.pay_code}">
            <p><span >{$vo.pay_name}</span></p>
        </div>
        {/volist}
        <div class="am-u-sm-12" style="text-align: center;">
            <button type="button" class="am-btn am-btn-danger" onclick="doPay(this);">立即支付</button>
            <button type="button" class="am-btn am-btn-default">订单中心</button>
        </div>

    </form>
</div>
{/block}
{block name='script'}
<script src="/public/plugins/jquery.min.js"></script>
<script type="text/javascript" src="/public/plugins/timedown/jquery.yomi.js"></script>
<script src="/public/plugins/layerMobile/layer.js"></script>
<script>
    function setPay(obj) {
        var payCode = $(obj).data('code');
        $("input[name='pay_code']").val(payCode);
        $(obj).addClass('active').siblings().removeClass('active');
    }

    var device = $('#device').val();

    function doPay(obj) {
        var payCode = $("input[name='pay_code']").val();
        //余额支付 货到付款 线下付款
        if (payCode == 'userpay' || payCode == 'delivery' || payCode == 'line') {
            $.post("{:url('home/Order/userpay')}", $(obj).parent().serialize(), function (res) {
                if (res.code == 1) {
                    location.href = "{:url('home/Order/index')}";
                } else {
                    alert(res.msg);
                }
            });
        }
        //支付宝支付
        if (payCode == 'alipay') {
            $(obj).parents('#form').attr('action', "{:url('plus/Alipay/pay')}");
            $(obj).parents('#form').submit();
            return false;
        }
        //微信支付
        if (payCode == 'wxpay') {
            {eq name = "device" value = "3" }
            callpay();
            {else/}
                $.post("{:url('plus/Wxpay/pay')}", $(obj).parents('form').serialize(), function (res) {
                    if (res.code == 1) {
                        var url = "{:url('plus/Help/qrcode')}?qtext=" + res.data;
                        var html = '<img style="width: 80vw;height: " src="' + url + '" />';
                        layer.open({
                            content: html
                        });
                    } else {
                        alert(res.msg);
                    }
                });
                {/eq}
                }
            }
            {eq name = "device"value = "3"}
            //调用微信JS api 支付
            function jsApiCall() {
                WeixinJSBridge.invoke('getBrandWCPayRequest', {$jsApiParameters}, function (res) {
                        if (res.err_msg == "get_brand_wcpay_request:ok") {
                            location.href = "{:url('home/Order/index')}";
                            return false;
                        } else {
                            if (res.err_msg == "get_brand_wcpay_request:cancel") {
                                location.href = "{:url('home/Order/index')}";
                            } else {
                                alert('错误代码：' + res.err_code + '<br/>错误描述：' + res.err_desc + '<br/>错误：' + res.err_msg);
                            }
                        }
                    }
                );
            }

            //微信支付
            function callpay() {
                if (typeof WeixinJSBridge == "undefined") {
                    if (document.addEventListener) {
                        document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);
                    } else if (document.attachEvent) {
                        document.attachEvent('WeixinJSBridgeReady', jsApiCall);
                        document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
                    }
                } else {
                    jsApiCall();
                }
            }

            {/eq}
</script>
{/block}
